﻿using Common;
using Common.Entity;
using Common.SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1.控件
{
    public partial class LogContorl : UserControl
    {
        public LogContorl()
        {
            InitializeComponent();
            
        }

        private async void GetLogAndBindGridView()
        {
            if (!DesignMode)
            {
                DateTime startTime = uiDatePicker1.Value.Date;
                DateTime endTime = uiDatePicker1.Value.Date.AddDays(1);

                List<LogInfo> logs = await SqlSugarHelper.Instance.Db.Queryable<LogInfo>().Where(u => u.Time > startTime && u.Time < endTime && u.Info.Contains(uiTextBox1.Text)).ToListAsync();

                uiDataGridView1.DataSource = logs;
            }
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            GetLogAndBindGridView();
        }

        private void LogContorl_Load(object sender, EventArgs e)
        {
  
                ContorlGenerateHelper.SetGridPropertyAndName(uiDataGridView1, typeof(LogInfo));
                uiDatePicker1.Value = DateTime.Now;
                GetLogAndBindGridView();
            
        }
    }
}
